<template>

  <el-dialog
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    append-to-body
    title="错误反馈"
    width="40%"
    @close="handleClose"
  >


    <div style="padding-top: 20px">
      <el-form ref="postForm" :model="postForm" :rules="rules" label-width="120px" label-position="top">
        <el-form-item prop="content">
          <el-input v-model="postForm.content" type="textarea" placeholder="请详细描述题目错误的地方，采纳后可获得积分奖励哦~" rows="5" />
        </el-form-item>
      </el-form>
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="saveReport">确 定</el-button>
    </div>

  </el-dialog>
</template>

<script>
import { save } from '@/api/client/qu/report'

export default {
  name: 'QuReportDialog',
  props: {
    quId: String,
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogVisible: false,
      postForm: {
        content: ''
      },
      rules: {
        content: [
          { required: true, message: '错误描述不能为空！' }
        ]
      }
    }
  },

  watch: {
    quId: {
      handler(val) {
        this.postForm.quId = val
      }
    },
    visible: {
      handler() {
        this.dialogVisible = this.visible
        this.postForm.content = ''
      }
    }
  },

  created() {
    this.dialogVisible = this.visible
  },

  methods: {
    // 关闭回调
    handleClose() {
      this.$emit('update:visible', false)
    },

    // 提交发布
    saveReport() {
      this.$refs.postForm.validate((valid) => {
        if (!valid) {
          return
        }

        // 题目
        this.postForm.quId = this.quId

        save(this.postForm).then(() => {
          // 发布
          this.$message.success('提交成功，审核结果将通过站内信通知您！')
          this.handleClose()
        })
      })
    }
  }
}
</script>

<style scoped>

</style>

